
import utils.Singleton;

import std.stdio:writefln;

import Screen;
import Display;
import Object3d;

class World{
	mixin SingletonMix;

	void initialize(){
		display();
		screen();
	}

	void render(){
		
		screen.begin();
			drawWireFrame();
		screen.end();
	}

	void update(){
	}

	void drawWireFrame(){
		foreach(obj3d; objects3d){
			display.modelview(obj3d.position, obj3d.orientation);
			for(uint idx = 0; idx < obj3d.mesh.indices.length; idx += 3){
				//[idx, idx+1, idx+2]
				screen().drawWiredTriangle([obj3d.mesh.vertices[obj3d.mesh.indices[idx]],
									obj3d.mesh.vertices[obj3d.mesh.indices[idx+1]],
									obj3d.mesh.vertices[obj3d.mesh.indices[idx+2]] ]);
			}
		}
	}

	void attach(Object3d obj){
		objects3d ~= obj;
	}

	Object3d[] objects3d;
}

alias SingletonGetter!(World) world;
